package pokerGame.pokerDeck;

import java.util.Collection;
import java.util.ArrayList;
import java.util.Random;

public class Deck{
	private ArrayList<Card> deck = new ArrayList<Card>();
	private Collection usedCards = new ArrayList<Card>();
	private Random r = new Random();
	
	// This class could be made as a singleton.
	public Deck() {
		this(false); //Jokers must be asked for explicit.
	}
	
	public Deck(boolean withJoker) {
		for(Suit suit: Suit.values()) { //Foreach loop over all Suits.
			for(Value value: Value.values()) { //Foreach loop over all Values.
				deck.add(new Card(suit, value)); 
			}
		}
	}
	
	public Card drawCard() {
		Card drawnCard = deck.get(0);
		// This should be changed so that no cards are removed from the deck.
		// Maybe it could be added to the end of the deck.
		deck.remove(0);
		usedCards.add(drawnCard);
		return drawnCard;
	}
	
	public void shuffle() {
		deck.addAll(usedCards);
		Card tmpCard;
		int tmpInt;
		for(int i = 0; i < deck.size(); i++) {
			tmpCard = deck.get(i);
			tmpInt = r.nextInt(deck.size());
			deck.set(i, deck.get(tmpInt));
			deck.set(tmpInt, tmpCard);
		}
	}
	
	/**
	* This method could be added to a new class PokerDeck,
	* This class would then extend the Deck class.
	*/
	public void burnCard() {
		// This should be changed so that no cards are removed from the deck.
		// Maybe it could be added to the end of the deck.
		usedCards.add(deck.get(0));
		deck.remove(0);
	}
	
	/**
	* This method is for testing purpose only.
	*/
	public void printDeck() {
		int i;
		for(i = 0; i < deck.size(); i++) {
			deck.get(i).printCard();
		}
		System.out.println(i);
	}
}